/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InputLBGFrameDialog.java
 *
 * Created on 24/11/2009, 00:16:18
 */

package quantizacaovetorial;

import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.ListSelectionModel;

/**
 *
 * @author Guto
 */
public class InputLBGFrameDialog extends javax.swing.JDialog {

    private JFileChooser jFileChooser;
    Vector lista;

    /** Creates new form InputLBGFrameDialog */
    public InputLBGFrameDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        lista = new Vector();
        setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        labelTrainingSet = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        listTrainingSet = new javax.swing.JList();
        bntAdd = new javax.swing.JButton();
        bntRemove = new javax.swing.JButton();
        bntGenerateDictionary = new javax.swing.JButton();
        bntClean = new javax.swing.JButton();
        labelDimension = new javax.swing.JLabel();
        txtDimension = new javax.swing.JTextField();
        txtSize = new javax.swing.JTextField();
        labelSize = new javax.swing.JLabel();
        txtArquiveDestination = new javax.swing.JTextField();
        labelArquiveDestination = new javax.swing.JLabel();
        bntSearch = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        labelTrainingSet.setText("Conjunto de Treino:");

        jScrollPane1.setViewportView(listTrainingSet);

        bntAdd.setText("Adicionar");
        bntAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntAddActionPerformed(evt);
            }
        });

        bntRemove.setText("Remover");
        bntRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntRemoveActionPerformed(evt);
            }
        });

        bntGenerateDictionary.setText("Gerar Dicionário");
        bntGenerateDictionary.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntGenerateDictionaryActionPerformed(evt);
            }
        });

        bntClean.setText("Limpar Campos");
        bntClean.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntCleanActionPerformed(evt);
            }
        });

        labelDimension.setText("Dimensão:");

        txtDimension.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtDimensionActionPerformed(evt);
            }
        });

        txtSize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtSizeActionPerformed(evt);
            }
        });

        labelSize.setText("Tamanho:");

        txtArquiveDestination.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtArquiveDestinationActionPerformed(evt);
            }
        });

        labelArquiveDestination.setText("Arquivo Destino:");

        bntSearch.setText("...");
        bntSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bntSearchActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(labelTrainingSet)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                                .addComponent(bntAdd, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(bntRemove, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(45, 45, 45)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDimension, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelDimension)
                            .addComponent(txtSize, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(labelSize)
                            .addComponent(labelArquiveDestination)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(bntClean)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(bntGenerateDictionary, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(txtArquiveDestination, javax.swing.GroupLayout.PREFERRED_SIZE, 318, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(bntSearch))))))
                .addGap(16, 16, 16))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelTrainingSet)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(labelDimension)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDimension, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(labelSize)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(labelArquiveDestination)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtArquiveDestination, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(bntSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 170, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(bntGenerateDictionary)
                            .addComponent(bntClean)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 282, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(bntRemove)
                            .addComponent(bntAdd))))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void bntAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntAddActionPerformed

       lista.add(iniFileChooser());
       listTrainingSet.setListData(lista);

    }//GEN-LAST:event_bntAddActionPerformed

    private void bntGenerateDictionaryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntGenerateDictionaryActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_bntGenerateDictionaryActionPerformed

    private void txtDimensionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtDimensionActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtDimensionActionPerformed

    private void txtSizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtSizeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtSizeActionPerformed

    private void txtArquiveDestinationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtArquiveDestinationActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtArquiveDestinationActionPerformed

    private void bntRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntRemoveActionPerformed
        lista.remove(listTrainingSet.getSelectedIndex());
        listTrainingSet.setListData(lista);
    }//GEN-LAST:event_bntRemoveActionPerformed

    private void bntSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntSearchActionPerformed
        txtArquiveDestination.setText(iniFileChooser());
    }//GEN-LAST:event_bntSearchActionPerformed

    private void bntCleanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bntCleanActionPerformed
        txtArquiveDestination.setText(null);
        txtDimension.setText(null);
        txtSize.setText(null);
    }//GEN-LAST:event_bntCleanActionPerformed

   private String iniFileChooser(){
        jFileChooser = new JFileChooser();
        JFrame frame = new JFrame();
        jFileChooser.setVisible(true);
        jFileChooser.showOpenDialog(frame);
        String path = "";
        if(jFileChooser.getSelectedFile()!=null){
            path = jFileChooser.getSelectedFile().getAbsolutePath();
        }
        return path;
   }

   public void openInputLBGFrame(){
       InputLBGFrameDialog inputFrame = new InputLBGFrameDialog(new InitialFrame(), true);
       inputFrame.setVisible(true);
  }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bntAdd;
    private javax.swing.JButton bntClean;
    private javax.swing.JButton bntGenerateDictionary;
    private javax.swing.JButton bntRemove;
    private javax.swing.JButton bntSearch;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelArquiveDestination;
    private javax.swing.JLabel labelDimension;
    private javax.swing.JLabel labelSize;
    private javax.swing.JLabel labelTrainingSet;
    private javax.swing.JList listTrainingSet;
    private javax.swing.JTextField txtArquiveDestination;
    private javax.swing.JTextField txtDimension;
    private javax.swing.JTextField txtSize;
    // End of variables declaration//GEN-END:variables

}
